package org.jacp.demo.ui.perspective;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import org.jacp.api.action.IActionListener;
import org.jacp.api.componentLayout.Layout;
import org.jacp.swing.rcp.action.SwingAction;
import org.jacp.swing.rcp.componentLayout.SwingPerspectiveLayout;
import org.jacp.swing.rcp.perspective.ASwingPerspective;

import com.explodingpixels.macwidgets.IAppWidgetFactory;

public class EmployeeDemoPerspective extends ASwingPerspective {

	@Override
	public void handleBarEntries(final Map<Layout, Container> bars) {
		final Container toolBar = bars.get(Layout.NORTH);
		final JButton add = new JButton(new ImageIcon(Toolkit
				.getDefaultToolkit().getImage("NSImage://NSColorPanel")));
		add.setText("");

		add.putClientProperty("JButton.segmentPosition", "first");
		add.setFocusable(false);
		add.setSize(new Dimension(10, 10));
		final IActionListener<ActionListener, ActionEvent, Object> listener = getActionListener();
		listener.getAction().setMessage("id02", "test");
		add.addActionListener(listener.getListener());

		toolBar.add(add);
	}

	@Override
	public void handleMenuEntries(JMenu arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void handlePerspective(final SwingAction arg0,
			final SwingPerspectiveLayout layout) {
		final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
		splitPane.setDividerLocation(200);

		final JPanel containerLeft = new JPanel();
		final JScrollPane scrollPaneLeft = new JScrollPane(containerLeft);
		IAppWidgetFactory.makeIAppScrollPane(scrollPaneLeft);
		final JPanel containerRight = new JPanel();
		containerRight
				.setLayout(new BoxLayout(containerRight, BoxLayout.X_AXIS));

		final JScrollPane scrollPaneRight = new JScrollPane(containerRight);
		IAppWidgetFactory.makeIAppScrollPane(scrollPaneRight);
		layout.registerTargetLayoutComponent("left", scrollPaneLeft);
		layout.registerTargetLayoutComponent("right", scrollPaneRight);
		splitPane.setLeftComponent(scrollPaneLeft);
		splitPane.setRightComponent(scrollPaneRight);
		layout.setRootComponent(splitPane);

	}

}
